package ntrees.hu.accountteset;

import java.util.ArrayList;
import java.util.HashMap;

import android.accounts.Account;
import android.accounts.AccountManager;
import android.app.Activity;
import android.content.ContentResolver;
import android.content.SyncAdapterType;
import android.os.Bundle;
import android.util.Log;

public class AccountTestActivity extends Activity {
	private String TAG = "********  AccountTestActivity";
	private boolean LDEBUG = true;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        SyncAdapterType[] types = getContentResolver().getSyncAdapterTypes();
        for (int i = 0; i < types.length; i++) {
        	Log.d(TAG, "types: " + types[i].accountType);
        	Log.d(TAG, "types: " + types[i].authority);
        	Log.d(TAG, "types: " + types[i].isKey);
        }
        
        AccountManager am = AccountManager.get(this);
        Account[] accounts = am.getAccounts();
        Account account = null;
        for (int i = 0; i < accounts.length; i++) {
        	Log.d(TAG, "account: " + accounts[i].name);
        	Log.d(TAG, "account: " + accounts[i].type);
        	Log.d(TAG, "account: " + accounts[i].describeContents());
        	if (accounts[i].type.equals("ntrees.hu.renren")) {
                int syncState = ContentResolver.getIsSyncable(account, "ntrees.hu.renren.contentprovider");
                Log.d(TAG, "syncState: " + syncState);
        	}
        }  
    }
    
//    private void updateAccountCheckboxes(Account[] accounts) {
//        //mInvisibleAdapters.clear();
//
//        SyncAdapterType[] syncAdapters = ContentResolver.getSyncAdapterTypes();
//        HashMap<String, ArrayList<String>> accountTypeToAuthorities =
//            Maps.newHashMap();
//        for (int i = 0, n = syncAdapters.length; i < n; i++) {
//            final SyncAdapterType sa = syncAdapters[i];
//            if (sa.isUserVisible()) {
//                ArrayList<String> authorities = accountTypeToAuthorities.get(sa.accountType);
//                if (authorities == null) {
//                    authorities = new ArrayList<String>();
//                    accountTypeToAuthorities.put(sa.accountType, authorities);
//                }
//                if (LDEBUG) {
//                    Log.d(TAG, "onAccountUpdated: added authority " + sa.authority
//                            + " to accountType " + sa.accountType);
//                }
//                authorities.add(sa.authority);
//            } else {
//                // keep track of invisible sync adapters, so sync now forces
//                // them to sync as well.
//                //mInvisibleAdapters.add(sa.authority);
//            }
//        }
//
//        for (int i = 0, n = mCheckBoxes.size(); i < n; i++) {
//            getPreferenceScreen().removePreference(mCheckBoxes.get(i));
//        }
//        mCheckBoxes.clear();
//
//        for (int i = 0, n = accounts.length; i < n; i++) {
//            final Account account = accounts[i];
//            if (LDEBUG) Log.d(TAG, "looking for sync adapters that match account " + account);
//            final ArrayList<String> authorities = accountTypeToAuthorities.get(account.type);
//            if (authorities != null && (mAccount == null || mAccount.equals(account))) {
//                for (int j = 0, m = authorities.size(); j < m; j++) {
//                    final String authority = authorities.get(j);
//                    // We could check services here....
//                    int syncState = ContentResolver.getIsSyncable(account, authority);
//                    if (LDEBUG) Log.d(TAG, "  found authority " + authority + " " + syncState);
//                    if (syncState > 0) {
//                        addSyncStateCheckBox(account, authority);
//                    }
//                }
//            }
//        }
//    }
}